# 3.4嘉宾名单
guests = ['lisi', 'zhangsan', 'wangwu']
print("Hello",guests[0],"! I would like to invite you to my dinner.")
print("Hello",guests[1],"! I would like to invite you to my dinner.")
print("Hello",guests[-1],"! I would like to invite you to my dinner.")
# 3.5 修改嘉宾名单
print("zhangsan can't come to dinner.")
guests[1] = 'qianliu'
print("Hello",guests[0],"! I would like to invite you to my dinner.")
print("Hello",guests[1],"! I would like to invite you to my dinner.")
print("Hello",guests[-1],"! I would like to invite you to my dinner.")
# 3.6 添加嘉宾
print("I find a bigger table.")
guests.insert(0,'zhaoliu')# 在列表开头添加
guests.insert(2,'sunqi')# 在列表中间添加
guests.append('zhaojiu')# 在列表末尾添加
print("Hello",guests[0],"! I would like to invite you to my dinner.")
print("Hello",guests[1],"! I would like to invite you to my dinner.")
print("Hello",guests[2],"! I would like to invite you to my dinner.")
print("Hello",guests[3],"! I would like to invite you to my dinner.")
print("Hello",guests[4],"! I would like to invite you to my dinner.")
print("Hello",guests[-1],"! I would like to invite you to my dinner.")
# 3.7 缩减名单
print("I'm sorry that the table is not ready.")
guests.pop(0)
print("Sorry",guests[0],"! I cann't invite you to my dinner.")
guests.pop(0)
print("Sorry",guests[0],"! I cann't invite you to my dinner.")
guests.pop(0)
print("Sorry",guests[0],"! I cann't invite you to my dinner.")
guests.pop(0)
print("Sorry",guests[0],"! I cann't invite you to my dinner.")
print("\nHello",guests[0],"! I would like to invite you to my dinner.")
print("Hello",guests[-1],"! I would like to invite you to my dinner.")
# 使用del删除嘉宾
del guests[0]
del guests[-1]
print(guests)